<%-- 
    Document   : game
    Created on : 16/01/2012, 20:59:22
    Author     : elad
--%>
<%@page import="submarines.Board"%>
<%@page import="submarines.OnlineHumanPlayer"%>
<%@page import="submarines.Player"%>
<%@page import="submarines.PlayerManager"%>
<%@page import="submarines.Config" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
PlayerManager p = (PlayerManager)application.getAttribute("pManager");
String ssid = session.getId();
OnlineHumanPlayer me = (OnlineHumanPlayer)p.getPlayerBySession(ssid);
if (me == null) {
    me = p.getDeadPlayerByID(ssid);
    %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Battleships</title>
        <link rel="shortcut icon" href="images/favicon.ico" />
        <link rel="stylesheet" href="css/jquery-ui-1.8.16.custom.css" type="text/css" />
        <link rel="stylesheet" href="css/battleships.css" type="text/css" />
    </head>
    <body>
        <div id="mainBody">
            <div id="players">
                <div>We are sorry but you are no longer part of the game. <br />Please come back later</div>
            </div>
        </div>
    </body>
</html>
    <%
} else {

String[] players = p.getPlayerNames().clone();
int i, j;
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Battleships</title>
        <link rel="shortcut icon" href="images/favicon.ico" />
        <script type="text/javascript" src="js/jquery-1.7.1.js"></script>
        <script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
        <link rel="stylesheet" href="css/jquery-ui-1.8.16.custom.css" type="text/css" />
        <link rel="stylesheet" href="css/battleships.css" type="text/css" />
        <script type="text/javascript" src="js/playGame.js"></script>
    </head>
    <body>
        <div id="gameBody" style="position: relative; border-bottom-right-radius: 0px">
            <div id="statusBar">
                <div id="thisTurn">Now Playing: <span id="playingPlayer"></span></div>
                <div id="clockTurn"></div>
                <div id="gameClock"></div>
            </div>
            <div id="boards">
                <div id="board" style="display: block" data-owner="<%=me.getName()%>">
                    <div class="square"></div>
                    <%
                        for (i = Config.BOARD_START; i < Config.BOARD_SIZE + Config.BOARD_START; i++) {%>
                    <div class="square title"><%=(char) (i + 'A')%></div>   
                    <%                }

                        for (i = Config.BOARD_START; i < Config.BOARD_SIZE + Config.BOARD_START; i++) {%>
                    <div class="rowEnd"></div> 
                    <div class="square title"><%=i + 1%></div>   
                    <%
                        for (j = Config.BOARD_START; j < Config.BOARD_SIZE + Config.BOARD_START; j++) {%>
                    <div class="square" data-col="<%=j%>" data-row="<%=i%>"></div>
                    <%
                        }%>
                    <%}
                    %>
                    <div class="rowEnd"></div> 
                </div>
            <%
                for (int l = 0; l < players.length; l++) {
                    if (!players[l].equals(me.getName())) {
                        Board b = me.getCompetitorBoard(p.getPlayerByName(players[l]));
                        %>
                <div id="board" style="display: block" data-owner="<%=players[l]%>">
                    <div class="square"></div>
                    <%
                        for (i = Config.BOARD_START; i < Config.BOARD_SIZE + Config.BOARD_START; i++) {%>
                    <div class="square title"><%=(char) (i + 'A')%></div>   
                    <%                }

                        for (i = Config.BOARD_START; i < Config.BOARD_SIZE + Config.BOARD_START; i++) {%>
                    <div class="rowEnd"></div> 
                    <div class="square title"><%=i + 1%></div>   
                    <%
                        for (j = Config.BOARD_START; j < Config.BOARD_SIZE + Config.BOARD_START; j++) {%>
                    <div class="square" data-col="<%=j%>" data-row="<%=i%>"></div>
                    <%
                        }%>
                    <%}
                    %>
                    <div class="rowEnd"></div> 
                </div>
                        <%
                    }
                }
            %>                                      
            </div>
            <div id="players">
                <%
                String pName;
                pName = me.getName();
                %>
                    <h3><a href="#"><%=pName%></a></h3><div id="<%=pName%>" data-playerInfo="<%=pName%>"><p></p></div>
                <%
                for (int l = 0; l < players.length; l++) {
                    pName = players[l];
                    if (!pName.equals(me.getName())) {
                    %>
                    <h3><a href="#"><%=pName%></a></h3><div id="<%=pName%>" data-playerInfo="<%=pName%>"><p></p></div>
                    <%
                    }
                }
                %>
            </div>
               <button id="quit">
                <span class="ui-button-text">Quit Game</span>
            </button>
        </div>
        <div id="action"></div>
        <div id="errorMsg" title="Error"></div>
        <div id="computerAction"></div>
        <div id="confirmEaTurn"></div>
        <div id="addShip" title="Please choose ship and orientation">
    </body>
</html>
<script>
    tplayerName = "<%=me.getName()%>";
</script>

<%
}
%>